﻿@page
@model BookLink.Pages.Books.IndexModel

@{
    ViewData["Title"] = "书籍管理列表";
}

<h1>书籍管理列表</h1>

<p>
    <a asp-page="Create">新增</a>
</p>
<form>
    <p>
        <select asp-for="BookGenre" asp-items="Model.Genres">
            <option value="">全部</option>
        </select>
        书籍名称: <input type="text" asp-for="SearchString" />
        <input type="submit" value="搜索" />
    </p>
</form>
<table class="table table-sm text-nowrap">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Book[0].Title)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Book[0].ReleaseDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Book[0].Genre)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Book[0].Dowloadlink)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Book[0].Author)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Book[0].DownloadCount)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Book[0].IsVisible)
            </th>
            <th>管理</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.Book)
        {
            <tr>
                <td>
                     <a asp-page="./Details" asp-route-id="@item.Id">@Html.DisplayFor(modelItem => item.Title)</a> 
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ReleaseDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Genre)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.DowloadPath)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Author)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.DownloadCount)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.IsVisible)
                </td>
                <td>
                    <a asp-page="./Edit" asp-route-id="@item.Id">编辑</a> |
                    <a asp-page="./Details" asp-route-id="@item.Id">详情</a> |
                    <a asp-page="./Delete" asp-route-id="@item.Id">删除</a>
                </td>
            </tr>
        }
    </tbody>
</table>
@{
    var prevDisabled = !Model.Book.HasPreviousPage ? "disabled" : "";
    var nextDisabled = !Model.Book.HasNextPage ? "disabled" : "";
}

<div class="text-center">
    <a asp-page="./Index" asp-route-pageIndex="@(Model.Book.PageIndex - 1)" asp-route-bookGenre="@Model.BookGenre" asp-route-searchString="@Model.SearchString" class="btn btn-primary @prevDisabled">
        上一页
    </a>
    <a asp-page="./Index" asp-route-pageIndex="@(Model.Book.PageIndex + 1)" asp-route-bookGenre="@Model.BookGenre" asp-route-searchString="@Model.SearchString" class="btn btn-primary @nextDisabled">
        下一页
    </a>
</div>
